<?php

namespace app\admin\controller;

use app\BaseController;
use app\admin\model\Contribute as ContributeModel;

class Contribute extends BaseController
{
    public function list()
    {
        if (!$this->request->auth) return show(config('status.auth'), '认证失败');
        $page = input('page', 1, 'intval');
        $perpage = 10;
        $result = ContributeModel::order('id desc')->page($page, $perpage)->select();
        $total = ContributeModel::count();
        $data = [
            'total' => $total,
            'current' => $page,
            'perpage' => $perpage,
            'data' =>  $result
        ];
        return show(200, '列表', $data);
    }

    public function delete()
    {
        if (!$this->request->auth) return show(config('status.auth'), '认证失败');
        $id = input('id', 0, 'intval');
        $result = ContributeModel::destroy($id);
        if ($result) {
            return show(200, '删除成功');
        } else {
            return show(config('status.error_delete'), '删除失败');
        }
    }
}
